//
//  LKStatusCodeHandler.m
//  Live
//
//  Created by Pie on 2017/7/26.
//  Copyright © 2017年 LaKa. All rights reserved.
//

#import "LKStatusCodeHandler.h"
#import "LKRequestLocalCodeHandler.h"
#import "LKRequestErrorCode.h"
#import "BNDOfficeDocKit.h"

@implementation LKStatusCodeHandler

+ (void)respodStatusCode:(LKJsonStatusCode)code error:(NSError *)error;
{
    NSString *errorMsg = [error.userInfo[NSLocalizedDescriptionKey] copy];
    
    // 如果是网络链接出错
    if([LKRequestLocalCodeHandler isNetworkConnectErrorCode:code]) {
        
        errorMsg = [LKRequestLocalCodeHandler errorDescriptionWithErrorCode:(NSInteger)code];
        
        if(!NSStringIsEmpty(errorMsg)) {
            [ReminderHUD showReminderText:errorMsg delayTime:1.0];
        }
        return;
    }
    
    switch (code)
    {
        case LK_E_OK:
        {
            break;
        }
        case LK_E_FAIL_GET_DATA:
        {
            [ReminderHUD showReminderText:@"没有该数据，获取数据失败" delayTime:1.0];
            break;
        }
        case LK_E_INVALID_PARAM:
        case LK_E_GOODS_NOT_EXSIT:
        {
            [ReminderHUD showReminderText:@"商品不存在" delayTime:1.0];
            break;
        }
        case LK_E_GOODS_NOT_ENOUGH:
        {
            [ReminderHUD showReminderText:@"商品库存不足" delayTime:1.0];
            break;
        }
        case LK_E_INVALID_GOODS:
        {
            [ReminderHUD showReminderText:@"商品已下架" delayTime:1.0];
            break;
        }
        case LK_E_SEVER_BUSY:
        {
            [ReminderHUD showReminderText:@"服务器繁忙,请稍后再试" delayTime:1.0];
            break;
        }
        case LK_E_ORDER_NOT_EXIST: {
            [ReminderHUD showReminderText:@"订单不存在" delayTime:1.0];
            break;
        }
        default:{
            
            errorMsg = [errorMsg stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
            if (errorMsg.length > 0) {
                [ReminderHUD showReminderText:errorMsg delayTime:1.5];
            }else {
                [ReminderHUD showReminderText:[NSString stringWithFormat:@"错误：%@", @(code)] delayTime:1.5];
            }
            break;
        }
    }
}

@end
